Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jsonld templating playground #28

Merged
merged 18 commits into from
Oct 1, 2024
Merged

jsonld templating playground #28

merged 18 commits into from
Oct 1, 2024

Conversation

C-Loftus
Copy link
Member

@C-Loftus C-Loftus commented Sep 3, 2024

  • while written guides are very useful, they don't allow users to change individual keys and experiment with templating
    • users who need to template their data for Geoconnex may need to see a dynamic example for them to fully understand the instructions
  • it is helpful to have all three (raw json, the template, and the templated output) next to each other. In a standard docs page, this is too cramped since we have the sidebar and other items in the table of contents

In the page I added, users have 3 code editors. These are live editors with syntax highlighting and we can add schema validation if we want in the future as well. When they press the button, it applies the template to the raw json by calling a simple python backend service which applies the jinja template

  • If this seems like a reasonable idea, I can add pre-loaded examples so the users can select from the select box to switch been location/dataset oriented examples

Please don't merge since this requires a live python backend that is trivial and I have implemented locally, but this is not yet deployed to google cloud

image

@C-Loftus C-Loftus marked this pull request as draft September 3, 2024 02:11
Copy link

netlify bot commented Sep 3, 2024

Deploy Preview for docs-geoconnex-us ready!

Name Link
🔨 Latest commit ea2bfa0
🔍 Latest deploy log https://app.netlify.com/sites/docs-geoconnex-us/deploys/66fafad2e9c75d0008446a43
😎 Deploy Preview https://deploy-preview-28--docs-geoconnex-us.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ksonda
Copy link
Member

ksonda commented Sep 16, 2024

This is a really good idea. I would extend it, rather than starting with some raw GeoJSON output, have more of a builder, similar to https://technicalseo.com/tools/schema-markup-generator/

@C-Loftus
Copy link
Member Author

Sounds good, thanks for that link!

I agree there is value in a structured playground with dropdown options to guide, although I also think there is value in keeping an unstructured playground as another separate page (since a user may want to experiment generally / copy paste an arbitrary template/response).

The base functionality for the unstructured playground is close to done, just need the backend service live. Need to get a better idea of how we will be deploying back-end infra generally as we refactor scheduler (i.e. docker swarm vs k8s vs separate individual service etc). I can deploy it more simply if we don't want to be blocked on that.

@ksonda
Copy link
Member

ksonda commented Sep 16, 2024

If it can be containerized and accessed via http get/post then google cloud run is fine as an interim. But you should discuss with @adplincinst

@C-Loftus
Copy link
Member Author

Ben is going to walk me through the Google cloud credentials this upcoming week and I will set up cloud run; in the meantime, I experimented with adding sparnatural to this.
The react integration for sparnatural is a bit finicky since it is written in jquery but our build system is for react. Maybe in the future we can add it or have a separate site specifically for it, but at the moment it doesn't seem to be a good fit for our docs site.

Alternative, there is a langchain LLM loader for rdf graphs which I looked at as well: https://python.langchain.com/docs/integrations/graphs/rdflib_sparql/
While I think LLM's are overhyped, I do think that for a playground/exploration scenario, having the ability to generate sparql queries with natural language that conform to our schema makes it really easy for people to experiment. Another stretch goal, but I thought it was cool.

image

@ksonda
Copy link
Member

ksonda commented Sep 22, 2024

Spanatural or similar would be good if we can load it with the relevant types for us. Which we haven't actually specified they well. Probably some schema.org types for administrative boundaries and cuahsi site types.

@C-Loftus C-Loftus marked this pull request as ready for review September 26, 2024 21:30
@C-Loftus
Copy link
Member Author

@ksonda This should be good if you want to take a look at it. Made the UI a bit nicer and now have the Google cloud infra up and running for it.

@webb-ben let me know if you think I should change anything in the ## Templating Help part of the templating playground. I wasn't sure if there is a better way to explain why pygeoapi has us use data for the properties key.

@webb-ben
Copy link
Member

@webb-ben let me know if you think I should change anything in the ## Templating Help part of the templating playground. I wasn't sure if there is a better way to explain why pygeoapi has us use data for the properties key.

data is the python dictionary of the feature JSON-LD response that pygeoapi automatically generates. This does include flattening all of the objects in the properties block to the top level (ref). Not sure the cleanest way to explain that. But for sure the example JSON-LD should not have properties block

@C-Loftus

This comment was marked as resolved.

@webb-ben
Copy link
Member

Once we also have settled on the code for the function in GCP can we archive that somewhere in this repository?

@ksonda
Copy link
Member

ksonda commented Sep 30, 2024

The template playground doesnt' seem to work for some reason. Maybe we need to pick a simpler example, like from one of the state gage endpoints where wha'ts coming through is just one table as geojson

Copy link
Member Author

@C-Loftus C-Loftus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ksonda if it wasn't working that is probably since I was working on making some changes after Ben and I aligned this morning. Should be working now.

Ben, please feel free to suggest / edit directly anything if I am still misunderstanding.

Comment on lines +10 to +13
@functions_framework.http
def templating(request: flask.Request):
"""HTTP Cloud Function.
Args:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@webb-ben here is the backend code

Comment on lines +52 to +58
const templatingRequest = {
source_values: {
// we create a top level data key to mimic the fact pygeoapi does it
data: dataToSend,
},
template: template,
};
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of doing this on the backend, i think it is easiest to just wrap the jsonld with a data key to mimic what pygeoapi is doing. Works for me. But wanted to confirm that this is reasonable

Notes on templating within pygeoapi
</div>

When pygeoapi applies a Jinja template, it considers the entire source JSON-LD to be the top-level key named `data`. Otherwise, the Jinja templating in pygeoapi is standard and follows expected patterns.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct?

@webb-ben webb-ben merged commit 9305369 into main Oct 1, 2024
4 checks passed
@webb-ben webb-ben deleted the playground branch October 1, 2024 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants